/*
exampleBBSelector: example of use for Backbones Selector project.
    Copyright (C) 2012  Jorge E. A. Atala
                        Adrian Remonda
                        FuDePAN
    This file is part of the Backbones-Selector Proyect.

    Backbones-Selector is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    Backbones-Selector is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with Backbones-Selector.  If not, see <http://www.gnu.org/licenses/>.
*/


#include <gtest/gtest.h>
#include <gmock/gmock.h>
#include <iostream>
#include <mili/mili.h>
using namespace mili;
#include <feca/feca.h>
#include <prot-filer/xtc_filer.h>
#include <prot-filer/cached_reader.h>
#include "backbones-selector/ranker/backbones-selector.h"

//Compile with -lprot-filer option!!!!!

using namespace  backbonesSelector;
using namespace prot_filer;

namespace prot_filer
{
ostream& operator<<(ostream& os, const Coord3d& c)
{
    return os << "(" << c.x << ", " << c.y << ", " << c.z << ")";
}
}

TEST(basic_test, test)
{
    //Create an energy Table from data file
    const EnergyTable<float, float> energyTable("ref/matrixData.txt");

    //create an example aminoacid Sequence
    const AminoacidSequence aminoacidsSt = "AWYCDMQNKHVVRGPTDQEMTAHQWKRNWWHGNKRYCCPDQEEVC";

    //Create ranker
    Ranking proteinRanker(10);

    //Create selector
    backbonesSelector::Selector<float, float> machine(energyTable, proteinRanker, aminoacidsSt);

    //read structures from xtc file and add structures to the selector,
    //when an Structure is added, the selector work with the ranker
    //and make a ranking with the best Structures
    CachedReader<FullCache, Coord3DReader,  Structure< > > r(Coord3DReaderFactory::get_instance()->create("xtc"));
    r.open("ref/test.xtc");
    unsigned int i = 0;
    Structure< >* protein = NULL;
    while ((protein = r.read(i)) != NULL)
    {
        machine.addStructure(*protein);
        ++i;
    }
    r.close();

    //Do something with the result (i.e. show the energy for the top ten proteins)
    mili::CAutonomousIterator<Ranking> rankingIterator(proteinRanker);
    while (!rankingIterator.end())
    {
        std::cout << (*rankingIterator)->getEnergy() << "\n";
        ++rankingIterator;
    }
}

